//
// Created by lenovo on 2024/1/11.
//

#include "Operator.h"
#include <cmath>
#include <iostream>
double Operator::getValue() {

    if (this->OptType == "+"){
        return this->pre->getValue() + this->post->getValue();
    }
    if (this->OptType == "-") {
        return this->pre->getValue() - this->post->getValue();
    }
    if (this->OptType == "*") {
        return this->pre->getValue() * this->post->getValue();
    }
    if (this->OptType == "/") {
        return this->pre->getValue() / this->post->getValue();
    }

    if (this->OptType == "**"){
        return std::pow(
                this->pre->getValue() ,
                this->post->getValue()
                );
    }
    else{
        throw std::invalid_argument("Invalid Operator Type");
    }
    return 0;
}
